<?php
Configure::write('LilcartPlugin.tablePrefix', '');
App::import('Model', 'Lilcart.Category');

class TestCategory extends Category {
	var $cacheSources = false;
	var $useDbConfig  = 'test_suite';
}

class CategoryTestCase extends CakeTestCase {
	var $Category = null;
	var $fixtures = array('plugin.lilcart.item', 'plugin.lilcart.category', 'plugin.lilcart.categories_item');

	function start() {
		parent::start();
		$this->Category = new TestCategory();
	}

	function testCategoryInstance() {
		$this->assertTrue(is_a($this->Category, 'Category'));
	}

	function testCategoryFind() {
		$this->Category->recursive = -1;
		$results = $this->Category->find('first');
		$this->assertTrue(!empty($results));

		$expected = array('Category' =>	array(
			'id'  => 1,
			'parent_id'  => null,
			'lft'  => 1,
			'rght'  => 14,
			'items_count'  => 3,
			'title'  => 'TOP - types',
			'slug'	=> 'top-types',
			'locked' => 1,
			'created'  => '2008-09-01 20:22:22',
			'modified'  => '2008-09-01 20:22:22'
		));
		$this->assertEqual($results, $expected);
	}
	
	function testLookup() {
		$expected = 4;
		$result = $this->Category->lookup('top-types/computers/desktop');
		$this->assertEqual($result, $expected);
		
		$expected = 5;
		$result = $this->Category->lookup(array('top-types', 'computers', 'workstations'));
		$this->assertEqual($result, $expected);
	}
	
	function testChildrenWithItems() {
		$expected = array(10);
		$data = $this->Category->childrenWithItems(8, array(5));
		$this->assertEqual(Set::extract($data, '{n}.Category.id'), $expected);
	}
}
?>